import { useEffect, useState } from 'react';
import request from 'umi-request';

const useWeather = () => {
  // 天气的接口网站
  // https://www.nowapi.com/api/weather.realtime
  // http://api.k780.com/?app=weather.realtime&weaId=94&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json
  const [wtNm, setWtNm] = useState<string>('');
  const [wtTemp, setWtTemp] = useState<string>('');

  useEffect(() => {
    request
      .get(
        'http://api.k780.com/?app=weather.realtime&weaId=94&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json',
      )
      .then((res) => {
        setWtNm(res.result.realTime.wtNm);
        setWtTemp(res.result.realTime.wtTemp);
      });
  }, []);

  return [wtNm, wtTemp];
};

export default useWeather;
